package what.the.fun.dao;

import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import what.the.fun.domain.AnswerResult;
import what.the.fun.jdbc.AnswerResultRowMapper;

public class AnswerResultDAOImpl implements AnswerResultDAO{

	@Autowired
	DataSource dataSource;
	JdbcTemplate jdbcTemplate;
	String sql;
	
	@Override
	public List<AnswerResult> getDataList() {
		sql = "call sp_answer_result_GetAll ()";
		jdbcTemplate = new JdbcTemplate(dataSource);
		
		List<AnswerResult> list = new ArrayList<AnswerResult>();
		list = jdbcTemplate.query(sql, new AnswerResultRowMapper());
		
		return list;
	}

	@Override
	public void insertData(AnswerResult data) {
		sql = "call sp_answer_result_Insert (?, ?)";
		jdbcTemplate = new JdbcTemplate(dataSource);
		
		jdbcTemplate.update(sql, data.getResultId(), data.getAnswerId());
	}

	@Override
	public void updateData(AnswerResult data) {
		sql = "call sp_answer_Update (?, ?)";
		jdbcTemplate = new JdbcTemplate(dataSource);
		
		jdbcTemplate.update(sql, data.getResultId(), data.getAnswerId());
	}

	@Override
	public void deleteData(String id) {
		//TODO : need 2 parameters for 2 primary key of table answer_result
		sql = "call sp_answer_result_Delete (?)";
		jdbcTemplate = new JdbcTemplate(dataSource);
		
		jdbcTemplate.update(sql, id);
	}

	@Override
	public AnswerResult getData(String id) {
		//TODO : need 2 parameters for 2 primary key of table answer_result
		return null;
	}

}
